<template>
	<div class="ratings" v-loading="loading">
		<div class="ratings__title">
			<div class="ratings__title--item">
				<i class="iconfont icon-xiaolian good"></i>
				<span>好评数:&nbsp;{{ratings.good_ratings}}</span>
			</div>
			<div class="ratings__title--item">
				<i class="iconfont icon-Bad bad"></i>
				<span>差评数:&nbsp;{{ratings.bad_ratings}}</span>
			</div>
			<div class="ratings__title--item">
				<i class="iconfont icon-baifenbi rate"></i>
				<span>好评率:&nbsp;{{goodRate}}%</span>
			</div>
		</div>
		<div class="ratings__list" v-for="item in ratings.ratings">
			<div class="ratings__list--head">
				<img :src="item.img" alt="" />
			</div>
			<div class="ratings__list--content">
				<div class="college">{{item.college}}<div class="time">2017-08-09</div></div>
				<div class="says">{{item.says}}</div>
			</div>
		</div>
	</div>
</template>

<script>
	import { fetchUserInfoRatings } from "../../../../../api/api.js"
	export default {
		data() {
			return {
				loading: true,
				ratings: {}
			};
		},
		created() {
			this.getRatings();
		},
		methods: {
			getRatings() {
				this.loading = true;
				fetchUserInfoRatings().then( res => {
					this.loading = false;
					this.ratings = res.data.result;
				} ).catch( err => {
					alert(err);
					console.log(err);
				} );
			}
		},
		computed: {
			goodRate() {
				if (this.ratings.good_ratings) {
					const all = this.ratings.good_ratings + this.ratings.bad_ratings;
					const good = this.ratings.good_ratings;
					const percentage = (good / all * 100).toFixed(2);
					return percentage;
				}else {
					return 0;
				}

			}
		}
	}
</script>

<style lang="scss" scoped>
	.ratings {
		min-height: rem(250);
		font-size: $font-xs;
		padding: $com-padding-lr-base;
	}
	.ratings__title {
		display: flex;
		align-items: center;
		justify-content: space-around;
	}
	.ratings__title--item {
		.good {
			color: $color-success;
		}
		.bad {
			color: $color-danger;
		}
		.rate {
			color: $color-info;
		}
	}
	.ratings__list {
		margin-top: rem(15);
		display: flex;
		border-bottom: 1px solid #eee;
	}
	.ratings__list:not(:last-child) {
		padding-bottom: rem(20);
	}
	.ratings__list--head {
		flex-shrink: 0;
		@include round-header-small;
		margin-right: rem(8);
	}
	.ratings__list--content {
		.college {
			font-size: $font-xs;
			color: $gray-light;
		}
		.time {
			margin-top: rem(5);
			font-size: $font-xs;
			color: $gray-light;
		}
		.says {
			color: $gray-dark;
			font-size: $font-sm;
			margin-top: rem(4);
		}
	}
</style>